<?php
//封装
class pdo1
{
    public $dbh;
    //构造类的实例化
    public function __construct()
    {
        $this->dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
    }
    //添加
    public function insert($arr,$table)
    {
          $k='';
          $v='';
        foreach($arr as $key=>$value)
        {
            $k.=$key.',';
            $v.="'$value'".",";
        }
        $k=substr($k,0,-1);
        $v=substr($v,0,-1);
        $sql="insert into $table ($k) VALUES ($v)";
        $this->dbh->exec($sql);
        return $this->dbh->lastInsertId();

    }

}